<?
$q = getValue('q','str','GET','');
$q = htmlspecialbo($q);
if(!$q){
    //Giao dien tim kiem
?>
<div class="sintf">
    <h6 class="sintf_title font colorbase">Nhập tiêu chí tìm kiếm</h6>
    <div class="sintf_main rlt">
        <form class="form-search">
            <input type="text" name="q" placeholder="Tìm bạn theo tên, theo thông tin cá nhân..." class="sintf_isearch"/>
            <button type="submit" class="sintf_submit btn_small abs">Tìm kiếm</button>
            <div class="sintf_chosen">
                <div class="control-group">
                    <div class="controls">
                        <label class="radio">
                            <input type="radio" name="chosen" value="1" checked="checked"/>Theo tên
                        </label>
                    </div>
                </div>
                <div class="control-group">
                    <div class="controls">
                        <label class="radio">
                            <input type="radio" name="chosen" value="2"/>Theo thông tin cá nhân
                        </label>
                    </div>
                </div>
                <div class="control-group">
                    <div class="controls">
                        <label class="radio">
                            <input type="radio" name="chosen" value="3"/>Theo sở thích
                        </label>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<?
}
else{
    //Search theo các tiêu chí
    $chosen = getValue('chosen','int','GET',0);
    $total = 0;
    $list_result = array();
    switch($chosen){
        case 1:
        //Search theo tên
        $db_count = new db_count('SELECT count(*) as count FROM users WHERE use_login LIKE "%'.$q.'%"');
        $total = $db_count->total;unset($db_count);
        $db_result = new db_query('SELECT use_id,use_login,use_avatar
                                    FROM users 
                                    WHERE use_login LIKE "%'.$q.'%" 
                                    LIMIT 30');
        $list_result = $db_result->resultArray();
        break;
        case 2:
        //Search theo thông tin cá nhân
        $db_count = new db_count('SELECT count(*) as count FROM users WHERE use_info LIKE "%'.$q.'%"');
        $total = $db_count->total;unset($db_count);
        $db_result = new db_query('SELECT use_id,use_login,use_avatar
                                    FROM users 
                                    WHERE use_info LIKE "%'.$q.'%" 
                                    LIMIT 30');
        $list_result = $db_result->resultArray();
        break;
        default:
        //Search theo tên
        $db_count = new db_count('SELECT count(*) as count FROM users WHERE use_login LIKE "%'.$q.'%"');
        $total = $db_count->total;unset($db_count);
        $db_result = new db_query('SELECT use_id,use_login,use_avatar
                                    FROM users 
                                    WHERE use_login LIKE "%'.$q.'%" 
                                    LIMIT 30');
        $list_result = $db_result->resultArray();
        break;
    }
    ?>
    <div class="list_search_result fl">
        <span class="font colorbase">Tìm thấy <?=$total?> kết quả <?=($total > 30 ? ' - Hiển thị 30 kết quả đầu tiên' : '')?></span>
        <?if($list_result){?>
        <ul>
        <?foreach($list_result as $res):?>
            <li class="fl">
                <a href="<?=generate_profile_url($res)?>">
                    <div class="usrthumb fl">
                        <img src="<?=$path_images_avatar?>small_<?=($res['use_avatar'] ? $res['use_avatar'] : 'noavt.png')?>"/>
                    </div>
                </a>
                <div class="usrdetail fl">
                    <a href="<?=generate_profile_url($res)?>"><label class="font colorbase usrname"><?=$res['use_login']?></label></a>
                    <label data-connect-id="<?=$res['use_id']?>"><i class="icon-plus-sign"></i>Kết nối</label>
                    <label><i class="icon-comment"></i>Gửi tin nhắn</label> 
                    <label><i class="icon-gift"></i>Tặng quà</label>       
                </div>
            </li>
        <?endforeach;?>
        </ul>
        <?}?>
    </div>
<?    
}
?>
<script>
$('#header .nav li').removeClass('active');
$('#header .nav li:eq(2)').addClass('active');
</script>